﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;
using Utpl.Syllabus.Framework;
using Utpl.Syllabus.Framework.Core;
using Utpl.Syllabus.Framework.Web.UI;
using System.Configuration;
using Utpl.Syllabus.Nucleo.BL;

namespace Utpl.Reconocimiento.Web
{
    [NotAuthorize]
    public partial class Principal : SyPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!X.IsAjaxRequest)
                {
                    int rolId;
                    int.TryParse(Session[ConstantesBL.ROL].ToString(), out rolId);
                    var rol = SyllabusApplication.Instance().GetCurrentUser().Roles.FirstOrDefault(r => r.RolId == rolId);
                    var rolesEqv = ConfigurationManager.AppSettings["RolesEquivalencias"].Split(',');
                    var rolesRec = ConfigurationManager.AppSettings["RolesReconocimiento"].Split(',');
                    if (rolesEqv.Count(p => p == rol.Codigo) == 1)
                    {
                        pnlLinks.Html =
                            string.Format(
                                "<a class=\"titleLink\" href=\"{0}\" target=\"blank\"  > Administraci&oacute;n de Equivalencias</a><br>",
                                ConfigurationManager.AppSettings["LinkEquivalencias"]);
                    }
                    if (rolesRec.Count(p => p == rol.Codigo) == 1)
                    {
                        pnlLinks.Html +=
                            string.Format(
                                "<a class=\"titleLink\" href=\"{0}\" target=\"blank\"  > Reconocimientos de Estudio</a><br>",
                                ConfigurationManager.AppSettings["LinkReconocimientos"]);
                    }
                }
            }
            catch (Exception ex)
            {
                ManejadorExcepciones.HandleException(ex);
            }
        }
    }
}